package com.great.medical.common;

import java.io.Serializable;

public class ResultBody<T> implements Serializable
{
    private static final long serialVersionUID = -6190689122701100762L;

    /**
     * 响应编码
     */
    private int code = 0;
    /**
     * 提示消息
     */
    private String message;

    /**
     * 请求路径
     */
    private String path;

    /**
     * 响应数据
     */
    private T data;

    /**
     * http状态码
     */
    private int httpStatus;

    public ResultBody()
    {
        super();
    }

    public int getCode()
    {
        return code;
    }

    public String getMessage()
    {
        return message;
    }

    public String getPath()
    {
        return path;
    }

    public T getData()
    {
        return data;
    }

    public static ResultBody ok() {
        return (new ResultBody()).code(ErrorCode.OK.getCode()).msg(ErrorCode.OK.getMessage());
    }

    public static ResultBody failed() {
        return (new ResultBody()).code(ErrorCode.FAIL.getCode()).msg(ErrorCode.FAIL.getMessage());
    }


    public ResultBody code(int code)
    {
        this.code = code;
        return this;
    }

    public ResultBody msg(String message)
    {
        this.message = message;
        return this;
    }

    //不使用标准的错误描述，使用自定义的错误描述信息
    public ResultBody selfMsg(String errorMsg)
    {
        this.message = errorMsg;
        return this;
    }

    public ResultBody data(T data)
    {
        this.data = data;
        return this;
    }

    public ResultBody path(String path)
    {
        this.path = path;
        return this;
    }

    public ResultBody httpStatus(int httpStatus)
    {
        this.httpStatus = httpStatus;
        return this;
    }

    @Override
    public String toString()
    {
        return "ResultBody{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", path='" + path + '\'' +
                ", data=" + data +
                ", httpStatus=" + httpStatus +
                '}';
    }

}
